import Cookies from 'js-cookie'
const login = {
    state: {
        userInfo: {}, //保存用户信息
        branch: false, // 默认为总站账号
        logFlag: false
    },
    mutations: {
        handlerSetName(state, paras) {
            // console.log(paras)
            state.userInfo = paras; //保存登录的用户信息
            state.branch = paras.branch; //保存门店Id
            state.logFlag = true; //表示用户数据已经存在了
            // console.log(state.logFlag);
            //设置cookie 过期时间
            //设置一天
            Cookies.set('sidebarStatus', paras, { expires: 1 });
            //console.log(!+Cookies.get('sidebarStatus2'));
        },
        setRoles(state) {
            //获取cookie信息，保存到state中
            var paras = JSON.parse(Cookies.get('sidebarStatus'));
            //var paras = Cookies.get('sidebarStatus');
            state.userInfo = paras; //保存登录的用户信息
            state.branch = paras.branch; //保存门店Id
            state.logFlag = true; //表示用户数据已经存在了
            // console.log(state.logFlag);
        }
    },
    actions: {
        handleUserInfo(context, paras) {
            return new Promise((resolve, reject) => {
                context.commit('handlerSetName', paras)
                    //状态设置完毕，返回出去
                resolve()
            }).catch((error) => {
                //返回错误信息
                reject(error)
            })
        },
        GetInfo(context) {
            context.commit('setRoles')
        }
    },
    getters: {
        //store.getters.doneTodos
        doneTodos: state => {
            return state.storeId - 1;
        }
    }
}

export default login